﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using NUnit.Framework;
using PatriotCreations.JpegData;

namespace PatriotCreations.JpegData.Tests
{
    [TestFixture]
    public class XmpReaderTests
    {
        private string _textFile;
        private Stream _textFileSource;

        [SetUp]
        public void TestSetUp()
        {
            _textFile = "c:\\temp\\testFile.txt";
        }

        [TearDown]
        public void TestTearDown()
        {
            if (File.Exists(_textFile))
            {
                _textFileSource.Close();
                File.Delete(_textFile);
            }
        }

        [Test]
        [ExpectedException(typeof(InvalidDataException), ExpectedMessage = "Image stream is empty.")]
        public void TestEmptyStreamThrowsException()
        {
            // Empty file that will cause an exception.
            string fileName = "c:\\temp\\testFile.txt";
            _textFileSource =
                new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);

            XmpReader reader = new XmpReader(_textFileSource);
        }

        /// <summary>
        /// Put into place as converted string to date time.
        /// </summary>
        [Test]
        public void TestDateTaken()
        {
            string fileName =
                Path.Combine(Environment.CurrentDirectory, @"..\..\TestImages/Parade001.jpg");

            Stream imageSource =
                new FileStream(fileName, FileMode.Open, FileAccess.Read);

            XmpReader reader = new XmpReader(imageSource);

            Assert.AreEqual(new DateTime(2007, 11, 11, 12, 6, 5), reader.DateTaken);
        }
    }
}
